package com.community.zhihuishequ.utils.thread;

/**
 *
 */
public abstract class ThreadPoolTask<T> implements Runnable {
    protected String mName;
    protected boolean mRunOnMainThread;
    protected T mParameter;

    public abstract void doTask(T parameter);

    public ThreadPoolTask(String name) {
        mName = name;
    }

    public String getName() {
        return (mName == null ? "" : mName);
    }

    public void setParameter(T parameter) {
        mParameter = parameter;
    }

    @Override
    public void run() {
//        long ts;
//        if (ThreadPoolManager.OPTIMIZE_DEBUG && mRunOnMainThread) {
//            ts = System.currentTimeMillis();
//        }
        doTask(mParameter);
//        if (ThreadPoolManager.OPTIMIZE_DEBUG && mRunOnMainThread) {
//            RecordAnrTask.asyncRecordMainThread(mName, System.currentTimeMillis() - ts);
//        }
    }

    @Override
    public String toString() {
        return getName();
    }

    public void postLongTask() {
        ThreadPoolManager.postLongTask(this);
    }

    public void postShortTask() {
        ThreadPoolManager.postShortTask(this);
    }
}
